package co.yixiang.modules.shop.rest;

import co.yixiang.modules.shop.domain.YxInfo;
import co.yixiang.modules.shop.service.YxInfoService;
import co.yixiang.modules.shop.service.dto.YxInfoQueryCriteria;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.bouncycastle.cert.ocsp.Req;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api("图文管理")
@Controller
@RequestMapping("/api")
public class YxInfoController {
    @Autowired
    private YxInfoService yxInfoService;

    @ApiOperation("查询")
    @GetMapping(value = "/yxInfo")
//    @PreAuthorize("@el.check('admin','YXINFO_ALL','YXINFO_SELECT')")
    public ResponseEntity getYxInfo(YxInfoQueryCriteria criteria, Pageable pageable) {

        return new ResponseEntity(yxInfoService.queryAll(criteria, pageable), HttpStatus.OK);
    }

    @ApiOperation("新增")
    @PostMapping(value = "/yxInfo")
//    @PreAuthorize("@el.check('admin','YXINFO_ALL','YXINFO_CREATE')")
    public ResponseEntity create(@Validated @RequestBody YxInfo resources) {
        Long lg=System.currentTimeMillis()/1000;
        resources.setAddTime(lg.intValue());
        return new ResponseEntity(yxInfoService.create(resources), HttpStatus.CREATED);
    }

    @ApiOperation("修改")
    @PutMapping("/yxInfo")
//    @PreAuthorize("@el.check('admin','YXINFO_ALL','YXINFO_EDIT')")
    public ResponseEntity update(@Validated @RequestBody YxInfo resources) {
        yxInfoService.update(resources);
        return new ResponseEntity(HttpStatus.NO_CONTENT);
    }

    @ApiOperation("删除")
    @DeleteMapping(value = "/yxInfo/{id}")
//    @PreAuthorize("@el.check('admin','YXINFO_ALL','YXINFO_DELETE')")
    public ResponseEntity delete(@PathVariable Integer id) {
        yxInfoService.delete(id);
        return new ResponseEntity(HttpStatus.OK);
    }
}
